package com.mi.everyday.d_10001_序列化;

import java.io.*;

public class 测试类_持久化保存对象信息 {

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        序列化();
        反序列化();
    }


    //序列化-持久化对象
    private static void 序列化() throws IOException {
        BookEntity book = new BookEntity();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("序列化.txt"));
        objectOutputStream.writeObject(book);
    }

    //反序列化（把二进制数据，转换成对象）
    private static void 反序列化() throws IOException, ClassNotFoundException {
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("序列化.txt"));
        Object o = objectInputStream.readObject();
        BookEntity readObject = (BookEntity) o;
        System.out.println(readObject);
    }
}
